package com.sanjiahantang.youjiarole.module.common.views.impl;

/**
 * Created by admin on 2017/10/21.
 */

import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.views.Lable;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.common.beans.ConditionBean;
import com.sanjiahantang.youjiarole.module.common.presenters.SelectorPresenter;
import com.sanjiahantang.youjiarole.module.common.views.SelectorView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




/**
 * Created by zy on 2017/10/18.
 * 选择器页
 */

public class LoveActivity extends BaseMvpActivity<SelectorView, SelectorPresenter> implements SelectorView, View.OnClickListener {


    private boolean loadLocalDic;
    private String[] initIndex;
    Lable lable;
    String value="";
    String key="";
    Map<String,String> map;
    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public SelectorPresenter initPresenter() {
        return new SelectorPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_love);
        TextView title = (TextView) findViewById(R.id.title);
        String strTitle = getIntent().getStringExtra(KEY_TITLE);
        title.setText(strTitle);

        findViewById(R.id.fl_Left).setOnClickListener(this);
        findViewById(R.id.flIcon3).setVisibility(View.VISIBLE);
        findViewById(R.id.flIcon3).setOnClickListener(this);
        initIndex = getIntent().getStringArrayExtra("isSelect");
        lable= (Lable) findViewById(R.id.lable);
    }
    @Override
    public void initData() {
        if (getIntent().getBundleExtra(KEY_PARAM) == null) {
            loadLocalDic = false;
        } else {
            loadLocalDic = true;
            List<String> tags = new ArrayList<>();
            if (null != ConfigValue.favoritelist) {
                map = new HashMap<>();
                for (ConditionBean.SelectorData tag : ConfigValue.favoritelist) {
                    map.put(tag.getDicName(),tag.getDicCode());
                    tags.add(tag.getDicName());
                }
            }
            lable.setDataList(tags);//设置显示数据
            lable.setSelectBytext(initIndex);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_Left:
                finish();
                break;
            case R.id.flIcon3:
                value="";
                key="";
                if (ConfigValue.favoritelist != null && ConfigValue.favoritelist.size() > 0){
                    for (int i=0;i<lable.getSelectContent().size();i++){
                        value += lable.getSelectContent().get(i)+",";
                        key += map.get(lable.getSelectContent().get(i)) + ",";
                    }
                }


                System.out.println("key"+key);
                if (value.length() > 0){
                    value = value.substring(0,value.lastIndexOf(","));
                    key = key.substring(0,key.lastIndexOf(","));
                }

                Intent intent = new Intent();
                intent.putExtra("favoriteValue", value);
                intent.putExtra("favoriteKey", key);
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }
}